import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:provider/provider.dart';
import 'package:xws/helpers/no_splash.dart';
import 'package:xws/state/user_state.dart';
import 'package:xws/ui/splash/splash_page.dart';

import 'state/app_state.dart';
import 'utils/app_util.dart';
import 'utils/theme_util.dart';
import 'utils/tools_util.dart';

Future<void> main() async {
  /// 初始化工具
  await initTools();

  runApp(const XWS());
}

class XWS extends StatelessWidget {
  const XWS({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: <ChangeNotifierProvider<dynamic>>[
        ChangeNotifierProvider<UserState>.value(value: us),
        ChangeNotifierProvider<AppState>.value(value: apps),
      ],
      builder: (_, __) => MaterialApp(
        scrollBehavior: const NoSplashScrollBehavior(),
        navigatorKey: appNavigatorKey,
        title: '极享',
        supportedLocales: const <Locale>[Locale('zh', 'CN')],
        locale: const Locale('zh', 'CN'),
        localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
          GlobalMaterialLocalizations.delegate,
          GlobalCupertinoLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
        ],
        theme: ThemeData(
          splashFactory: NoSplash.splashFactory,
          primaryColor: const Color(0xff0c88ea),
          hoverColor: Colors.blueGrey,
          primarySwatch: themeSwatch,
          errorColor: Colors.red[300],
          textTheme: const TextTheme(
            bodyText1: TextStyle(color: Colors.black),
          ),
        ),
        darkTheme: ThemeData.dark().copyWith(
          splashFactory: NoSplash.splashFactory,
          hoverColor: Colors.blueGrey,
          errorColor: Colors.red[300],
          primaryColor: Colors.blueGrey,
          cardColor: Colors.black,
        ),
        home: const SplashPage(),
      ),
    );
  }
}
